package beans;

import database.DBController;
import domain.Paper;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.faces.model.SelectItem;

public class loginBean implements Serializable {

    protected DBController dbc;
    protected String fullname;
    protected Paper p = new Paper();    

    public Paper getP() {
        return p;
    }

    public void setP(Paper p) {
        this.p = p;
    }



    public String getFullname() throws SQLException {
        dbc = new DBController();
        fullname = dbc.getFullName(userId);
        return fullname;

    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }
    protected int userId;

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;

    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    private String password;
    private String username;

    public String checkValidate() throws SQLException {
        dbc = new DBController();
        
        ResultSet rs = dbc.loginValidate(username, password);
        
        if (rs.next()) 
        {
            if (rs.getInt("UserTypeId") == 1) 
            {
                return "judge";
            } 
            else 
            {
                setUserId(rs.getInt("UserId"));
                return "writer";
            }
        }
        return null;
    }
    
    
    public List<SelectItem> getMyAllPapers() throws SQLException 
    {
        System.out.printf("userId:%d \n",userId);
        dbc = new DBController();
        
        return dbc.getMyAllPapers(userId);
    }    

    public String logout() {
        return "true";
    }



}
